<template>
  <el-row style="height: 100%">
    <div id="main" style="height: 100%"></div>

  </el-row>
</template>

<script>
import * as echarts from 'echarts';
import {
  ToolboxComponent,
  TooltipComponent,
  GridComponent,
  LegendComponent
} from 'echarts/components';
import {
  BarChart
} from 'echarts/charts';
import {
  CanvasRenderer
} from 'echarts/renderers';

echarts.use(
    [ToolboxComponent, TooltipComponent, GridComponent, LegendComponent, BarChart, CanvasRenderer]
);

export default {
  name: "LineCharts",
  data() {
    return {
      msg: 'Welcome to Your Vue.js App',
      option: {
        title: {
          text: '订单情况(小时)'
        },
        tooltip: {
          trigger: 'axis'
        },
        legend: {
          data: ['总订单', '生产订单', "收购订单", "运输订单"]
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        toolbox: {
          feature: {
            saveAsImage: {}
          }
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            name: '总订单',
            type: 'line',
            stack: 'Total',
            data: [120, 132, 101, 134, 90, 230, 210]
          },
          {
            name: '生产订单',
            type: 'line',
            stack: 'Total',
            data: [220, 182, 191, 234, 290, 330, 310]
          },
          {
            name: '收购订单',
            type: 'line',
            stack: 'Total',
            data: [150, 232, 201, 154, 190, 330, 410]
          },
          {
            name: '运输订单',
            type: 'line',
            stack: 'Total',
            data: [320, 332, 301, 334, 390, 330, 320]
          },
          // {
          //   name: 'Search Engine',
          //   type: 'line',
          //   stack: 'Total',
          //   data: [820, 932, 901, 934, 1290, 1330, 1320]
          // }
        ]
      }
    }
  },
  mounted() {
    this.drawLine()
  },
  methods: {
    drawLine() {

      // this.option && myChart.setOption(this.option);
      this.axios.get('/order_line_chart', {
        headers: {
          'content-type':'application/json',
          'token':this.$cookies.get("token")
        }
      }).then((res)=>{
            if (res.data.code === 200) {
              let timeList = res.data.data.time;
              let orderList = res.data.data.order;
              let produce = res.data.data.produce;
              let buy = res.data.data.buy;
              let ship = res.data.data.ship;
              this.option.xAxis.data = timeList
              this.option.series[0].data = orderList
              this.option.series[1].data = produce
              this.option.series[2].data = buy
              this.option.series[3].data = ship
              var chartDom = document.getElementById('main');
              var myChart = echarts.init(chartDom);
              this.option && myChart.setOption(this.option);
            }
          })
          .catch((res)=>{
            console.log(res);
          })
    }
  }
}
</script>

<style scoped>


</style>